package com.it.service.impl;

import com.it.common.Result;
import com.it.dao.SingerMapper;
import com.it.domain.Singer;
import com.it.service.SingerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SingerServImpl implements SingerService {

    @Autowired
    private SingerMapper singerMapper;

    @Override
    public Object AddSinger(Singer singer) {

        Singer singer1 = singerMapper.SelectIsExist(singer.getName().trim(), singer.getSex());
        if(singer1 != null){

            return Result.fail("404","歌手已存在");
        }

        if(singerMapper.AddSinger(singer)>0){
            return Result.success("200","添加成功");
        }
        else {
            return Result.fail("404","添加失败");
        }
    }

    @Override
    public boolean updateSinger(Singer singer) {
        return singerMapper.updateSinger(singer)>0;
    }

    @Override
    public boolean deleteSinger(Integer id) {
        if(singerMapper.deleteSinger(id)>0){
            return true;
        }
        else{
            return false;
        }
    }

    @Override
    public Singer SelectBid(Integer id) {
        return singerMapper.SelectBid(id);
    }

    @Override
    public List<Singer> SelectAll(Integer PageNum,Integer PageSize,String name) {
        return singerMapper.SelectAll(PageNum,PageSize,name);
    }

    @Override
    public List<Singer> SelectByName(String name) {
        return singerMapper.SelectByName(name);
    }

    @Override
    public Integer SelectTotal() {
        return singerMapper.SelectTotal();
    }

    @Override
    public List<Singer> GetAll() {
        return singerMapper.GetAll();
    }

    @Override
    public List<Singer> getSingerLists(Integer[] ids) {
        return singerMapper.getSingerLists(ids);
    }
}
